package server;

import common.DataTransferObject;

import java.net.*;
import java.io.*;
import java.sql.SQLException;

public class MultiServerThread extends Thread {
    private Socket socket = null;

    public MultiServerThread(Socket socket) {
        super("MultiServerThread");
        this.socket = socket;
    }

    public void run() {

        try {
            ObjectOutputStream out = new ObjectOutputStream(socket.getOutputStream());
            ObjectInputStream in = new ObjectInputStream(socket.getInputStream());
            MyProtocol protocol = new MyProtocol();
            boolean working = true;
            while (working) {
                DataTransferObject input = (DataTransferObject)in.readObject();
                DataTransferObject output = protocol.processInput(input);
                out.writeObject(output);
            }
            out.close();
            in.close();
            socket.close();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }
    }
}